package com.ctbri.gui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.Timer;

import com.ctbri.util.SwingConsole;

public class Ex7 extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JMenuItem mi = new JMenuItem("Menu Item");
	private JTextField txt = new JTextField(30);
	private JButton b1 = new JButton("Button 1");
	private JComboBox<String> jcb = new JComboBox<>(new String[]{
			"Elements", "To", "Place", "In", "ComboBox"
	});
	private JFileChooser jfc = new JFileChooser(".");
	public Ex7() {
		setLayout(new FlowLayout());
		add(mi);
		add(txt);
		add(b1);
		add(jcb);
		add(jfc);
		b1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				txt.setText("Button pressed");
			}
		});
		txt.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, 
						"JTextField ActionListener fired", 
						"information", 
						JOptionPane.INFORMATION_MESSAGE);
			}
		});
		jcb.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				txt.setText("JComboBox selected: " + jcb.getSelectedItem());
			}
		});
		jfc.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				txt.setText("FileChooser ActionListener fired: " + jfc.getSelectedFile());
			}
		});
		mi.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				txt.setText("JMenuItem selected");
			}
		});
		new Timer(5000, new ActionListener(){
			int i = 0;
			public void actionPerformed(ActionEvent e) {
				txt.setText("Timer Ticked " + i++);
			}
		}).start();
	}
	public static void main(String[] args) {
		SwingConsole.run(new Ex7(), 550, 400);
	}

}
